package com.cqw.commontest.lambda;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-02 15:23
 * @Description: 提取组合:
 * 流也可以进行合并，去重，限制，跳过等操作
 */
public class StreamTest10 {

    public static void main(String[] args) {
        String[] arr1 = {"a", "b", "c"};
        String[] arr2 = {"d", "e", "f", "c"};

        Stream<String> arr1Stream = Arrays.stream(arr1);
        Stream<String> arr2Stream = Arrays.stream(arr2);

        //合并
        List<String> collect = Stream.concat(arr1Stream, arr2Stream).collect(Collectors.toList());
        System.out.println(collect);

        //去重
        List<String> collect1 = collect.stream().distinct().collect(Collectors.toList());
        System.out.println(collect1);

        //只要前3个
        List<String> collect2 = collect1.stream().limit(3).collect(Collectors.toList());
        System.out.println(collect2);

        //跳过第一个
        List<String> collect3 = collect2.stream().skip(1).collect(Collectors.toList());
        System.out.println(collect3);

    }

}
